import numpy as np
import pandas as pd
from pandas import DataFrame as df
import matplotlib.pyplot as plt
import seaborn as sns
canada = pd.read_excel('https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DV0101EN/labs/Data_Files/Canada.xlsx',
sheet_name='Canada by Citizenship',
skiprows=range(20),
skipfooter=2)
canada.head()
#spare df
canada1 = canada
canada.rename(columns={'OdName':'Country', 'AreaName':'Continent', 'RegName':'Continent-Region'}, inplace=True)
canada.drop(['AREA','REG','DEV','Type','Coverage'], inplace=True, axis='columns')
canada.isnull().sum().sum()
canada.head(5)
canada.index.values
canada.set_index('Country', inplace=True)
canada.head()
canada.dtypes
canada.columns = list(map(str,canada.columns));
canada[canada['Continent']=='Asia'].head(4)
years = list(map(str,range(1980,2014)))
india_imgt = canada.loc['India', years]
india_imgt.plot(figsize=(10,6));
india_imgt.plot(kind='line');
plt.title('Immigration from India');
plt.ylabel('Number of immigrants');
plt.xlabel('Years');
canada.loc[['China','India'], years].transpose().plot(figsize =(10,7));
plt.title('Immigration of China and India');
plt.xlabel('Years');
plt.ylabel('Immigrants');
top5_clean = canada.head(5)[years].transpose()
top5_clean.index
top5_clean.index = top5_clean.index.map(int)
top5_clean.plot(kind="area", stacked=False, figsize=(20,10), alpha=0.25)
plt.title('Immigration trends in top five countries (1980-2013)')
plt.xlabel('Years')
plt.ylabel('Immigrants count')
plt.show()
top5_clean.plot(kind="area", stacked=True, figsize=(20,10), alpha=0.25)
plt.title('Immigration trends in top five countries (1980-2013)')
plt.xlabel('Years')
plt.ylabel('Immigrants count')
plt.show()
df_can = canada
df_can['2000'].plot(kind='hist', figsize=(20,10))
plt.title('Immigration trends in 195 countries in 2000')
plt.xlabel('Number of Immigrants')
plt.ylabel('Number of Countries')
plt.show()
df_can.loc[['India','China','Denmark','Norway','France','Germany'], years].transpose().plot.hist()
plt.title('Immigration trends in 6 countries in 1980-2013')
plt.xlabel('Number of Immigrants')
plt.ylabel('Number of Countries')
plt.show()
india = df_can.loc['India', years]
india.plot(kind='bar', figsize=(20,10))
plt.title('Immigration trends India immigrants from 1980 to 2013')
plt.xlabel('Years')
plt.ylabel('India immigrants from 1980 to 2013')
plt.show()
india = df_can.loc['India', years]
india.plot(kind='barh', figsize=(20,10))
plt.title('Immigration trends India immigrants from 1980 to 2013')
plt.xlabel('India immigrants from 1980 to 2013')
plt.ylabel('Years')
plt.show()
df_india = df_can.loc['India',years]
df_india.plot(kind='bar', figsize=(10,6))
plt.title("Indian immigration to Canada from 1980 to 2013")
plt.xlabel("Year")
plt.ylabel("Number of immigrants")
plt.annotate('', #arrow title
xy=(21,35000), #x,y of arrow head
xytext=(7,15000), #x, y of arrow tail
xycoords='data', #keep unchanged
arrowprops=dict(arrowstyle='->',color='red') #arrow style with color
)
plt.annotate('IT Boom', #add text to arrow
xy=(13,28000), #x, y of text position
rotation=40, # counter clockwise rotate text by angle
xycoords='data', #keep unchanged
va='top', #position text
ha='left') #position text
plt.show()
indopak = canada.loc[['India','Pakistan'], years].transpose()
indopak.reset_index(inplace=True)
indopak.rename(columns={'Country':'index','index':'Year'}, inplace=True)
indopak.head()
import numpy as np
x = indopak['Year'].astype('int64')
y = indopak['India']
fit = np.polyfit(x,y,deg=1)
print(fit)
indopak.plot(kind='scatter', x='Year', y='India', color='blue', figsize=(10,6))
plt.title('Total immigrants from India 1980-2013')
plt.xlabel("years")
plt.ylabel("Number of immigrants")
#plt.plot(x, fit[0]*x+fit[1], color='red')
plt.show();
ax0 = indopak.plot(kind='scatter', x='Year', y='India', color='blue', figsize=(10,6))
indopak.plot(kind='scatter', x='Year', y='Pakistan', color='green', figsize=(10,6), ax=ax0)
plt.title('Total immigrants from India and Pakistan 1980-2013')
plt.xlabel("years")
plt.ylabel("Number of immigrants")
ax0.legend(['India','Pakistan'], loc='upper left')
plt.show();
norm_india = (indopak['India'] - indopak['India'].min()) / (indopak['India'].max() - indopak['India'].min())
norm_pak = (indopak['Pakistan'] - indopak['Pakistan'].min()) / (indopak['Pakistan'].max() - indopak['Pakistan'].min())
ax0 = indopak.plot(kind='scatter', x='Year', y='India', color='blue', s=norm_india*200, figsize=(10,6))
indopak.plot(kind='scatter', x='Year', y='Pakistan', color='green', s=norm_india*200, figsize=(10,6), ax=ax0)
plt.title('Total immigrants from India and Pakistan 1980-2013')
plt.xlabel("years")
plt.ylabel("Number of immigrants")
ax0.legend(['India','Pakistan'], loc='upper left')
plt.show();
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
df_can['Total'] = df_can.sum (axis = 1)
# let's create a new dataframe for these three countries
df_dsn = df_can.loc[['Denmark', 'Norway', 'Sweden'], :]
# let's take a look at our dataframe
df_dsn
# compute the proportion of each category with respect to the total
total_values = sum(df_dsn['Total'])
category_proportions = [(float(value) / total_values) for value in df_dsn['Total']]
# print out proportions
for i, proportion in enumerate(category_proportions):
print (df_dsn.index.values[i] + ': ' + str(proportion))
width = 40 # width of chart
height = 10 # height of chart
total_num_tiles = width * height # total number of tiles
print ('Total number of tiles is ', total_num_tiles)
# compute the number of tiles for each catagory
tiles_per_category = [round(proportion * total_num_tiles) for proportion in category_proportions]
# print out number of tiles per category
for i, tiles in enumerate(tiles_per_category):
print (df_dsn.index.values[i] + ': ' + str(tiles))
# initialize the waffle chart as an empty matrix
waffle_chart = np.zeros((height, width))
# define indices to loop through waffle chart
category_index = 0
tile_index = 0
# populate the waffle chart
for col in range(width):
for row in range(height):
tile_index += 1
# if the number of tiles populated for the current category is equal to its corresponding allocated tiles...
if tile_index > sum(tiles_per_category[0:category_index]):
# ...proceed to the next category
category_index += 1
# set the class value to an integer, which increases with class
waffle_chart[row, col] = category_index
print ('Waffle chart populated!')
waffle_chart
# instantiate a new figure object
fig = plt.figure()
# use matshow to display the waffle chart
colormap = plt.cm.coolwarm
plt.matshow(waffle_chart, cmap=colormap)
plt.colorbar()
# instantiate a new figure object
fig = plt.figure()
# use matshow to display the waffle chart
colormap = plt.cm.coolwarm
plt.matshow(waffle_chart, cmap=colormap)
plt.colorbar()
# get the axis
ax = plt.gca()
# set minor ticks
ax.set_xticks(np.arange(-.5, (width), 1), minor=True)
ax.set_yticks(np.arange(-.5, (height), 1), minor=True)
# add gridlines based on minor ticks
ax.grid(which='minor', color='w', linestyle='-', linewidth=2)
plt.xticks([])
plt.yticks([])
# compute cumulative sum of individual categories to match color schemes between chart and legend
values_cumsum = np.cumsum(df_dsn['Total'])
total_values = values_cumsum[len(values_cumsum) - 1]
# create legend
legend_handles = []
for i, category in enumerate(df_dsn.index.values):
label_str = category + ' (' + str(df_dsn['Total'][i]) + ')'
color_val = colormap(float(values_cumsum[i])/total_values)
legend_handles.append(mpatches.Patch(color=color_val, label=label_str))
# add legend to chart
plt.legend(handles=legend_handles,
loc='lower center',
ncol=len(df_dsn.index.values),
bbox_to_anchor=(0., -0.2, 0.95, .1)
)
def create_waffle_chart(categories, values, height, width, colormap, value_sign=''):
# compute the proportion of each category with respect to the total
total_values = sum(values)
category_proportions = [(float(value) / total_values) for value in values]
# compute the total number of tiles
total_num_tiles = width * height # total number of tiles
print ('Total number of tiles is', total_num_tiles)
# compute the number of tiles for each catagory
tiles_per_category = [round(proportion * total_num_tiles) for proportion in category_proportions]
# print out number of tiles per category
for i, tiles in enumerate(tiles_per_category):
print (df_dsn.index.values[i] + ': ' + str(tiles))
# initialize the waffle chart as an empty matrix
waffle_chart = np.zeros((height, width))
# define indices to loop through waffle chart
category_index = 0
tile_index = 0
# populate the waffle chart
for col in range(width):
for row in range(height):
tile_index += 1
# if the number of tiles populated for the current category
# is equal to its corresponding allocated tiles...
if tile_index > sum(tiles_per_category[0:category_index]):
# ...proceed to the next category
category_index += 1
# set the class value to an integer, which increases with class
waffle_chart[row, col] = category_index
# instantiate a new figure object
fig = plt.figure()
# use matshow to display the waffle chart
colormap = plt.cm.coolwarm
plt.matshow(waffle_chart, cmap=colormap)
plt.colorbar()
# get the axis
ax = plt.gca()
# set minor ticks
ax.set_xticks(np.arange(-.5, (width), 1), minor=True)
ax.set_yticks(np.arange(-.5, (height), 1), minor=True)
# add dridlines based on minor ticks
ax.grid(which='minor', color='w', linestyle='-', linewidth=2)
plt.xticks([])
plt.yticks([])
# compute cumulative sum of individual categories to match color schemes between chart and legend
values_cumsum = np.cumsum(values)
total_values = values_cumsum[len(values_cumsum) - 1]
# create legend
legend_handles = []
for i, category in enumerate(categories):
if value_sign == '%':
label_str = category + ' (' + str(values[i]) + value_sign + ')'
else:
label_str = category + ' (' + value_sign + str(values[i]) + ')'
color_val = colormap(float(values_cumsum[i])/total_values)
legend_handles.append(mpatches.Patch(color=color_val, label=label_str))
# add legend to chart
plt.legend(
handles=legend_handles,
loc='lower center',
ncol=len(categories),
bbox_to_anchor=(0., -0.2, 0.95, .1)
)
width = 40 # width of chart
height = 10 # height of chart
categories = df_dsn.index.values # categories
values = df_dsn['Total'] # correponding values of categories
colormap = plt.cm.coolwarm # color map class
create_waffle_chart(categories, values, height, width, colormap)
indpakchi = canada.loc[['India', 'Pakistan', 'China'], :]
categories = list(indpakchi.index.values)
values = indpakchi['Total']
create_waffle_chart(categories, values, height, width, colormap)
canada['Total'].plot(kind='pie',figsize=(10,10));
can_continent = canada.groupby('Continent', axis='index').sum()
can_continent.head()
can_continent['Total'].plot(kind='pie', figsize=(7, 7));
can_continent['Total'].plot(kind='pie', figsize=(7, 7),
startangle = 180, autopct = '%1.1f%%')
plt.title('Immigration To Canada By Continents Between 1980 - 2013')
plt.axis('equal')
plt.legend(labels = can_continent.columns, loc='upper right')
plt.show()
can_devstatus = canada.groupby('DevName', axis='index').sum()
can_devstatus.head()
explodeList = [0.3,0]
colorList=['blue','magenta']
can_devstatus['Total'].plot(kind='pie', figsize=(7,7), startangle=90,autopct='%1.1f%%',
shadow=True, labels = None, colors = colorList, explode = explodeList)
plt.title('Immigration from 1980-2013 by development status')
plt.axis('equal')
plt.legend(labels= can_devstatus.index,loc ='upper right')
plt.show()
can_contreg = canada.groupby('Continent-Region', axis='index').sum()
can_contreg.head()
explodeList = [0.1]*22
#colorList=['blue','magenta']
can_contreg['Total'].plot(kind='pie', figsize=(10,10), startangle=90,autopct='%1.1f%%',
shadow=True, labels = None, explode = explodeList)
plt.title('Immigration from 1980-2013 by Continent-Region')
plt.axis('equal')
plt.legend(labels= can_contreg.index,loc ='upper right')
plt.show()
india = canada.loc['India', years]
india.plot(kind='box', figsize=(10,6))
plt.title('Box plot of India from 1980-2013')
plt.ylabel('Number of immigrants')
plt.show()
indopak = canada.loc[['India','Pakistan'], years].transpose()
indopak.plot(kind='box', figsize=(10,6))
plt.title('Box plot of India and Pakistan from 1980-2013')
plt.ylabel('Number of immigrants')
plt.show()
indopak.describe()
indopak.plot(kind='box', figsize=(10,6), color='red', vert=False)
plt.title('Box plot of India and Pakistan from 1980-2013')
plt.xlabel('Number of immigrants')
plt.show()
asia = canada[(canada['Continent']=='Asia')].sort_values('Total', ascending=False).head()
eur = canada[(canada['Continent']=='Europe')].sort_values('Total', ascending=False).head()
afr = canada[(canada['Continent']=='Africa')].sort_values('Total', ascending=False).head()
ocn = canada[(canada['Continent']=='Oceania')].sort_values('Total', ascending=False).head()
asia = asia[years].transpose()
eur = eur[years].transpose()
afr = afr[years].transpose()
ocn = ocn[years].transpose()
fig = plt.figure();
ax1 = fig.add_subplot(1,2,1);
eur.plot(kind='box', color='blue', vert=False, ax=ax1);
ax2 = fig.add_subplot(1,2,2);
asia.plot(kind='box', color='blue', vert=False, ax=ax2);
fig2 = plt.figure();
ax3 = fig2.add_subplot(1,2,1);
afr.plot(kind='box', color='blue', vert=False, ax=ax3);
ax4 = fig2.add_subplot(1,2,2);
ocn.plot(kind='box', color='blue', vert=False, ax=ax4);
temp = asia.describe()
Q1 = temp.loc['25%', 'Philippines']
Q3 = temp.loc['75%', 'Philippines']
IQR = Q3-Q1
Outlier1 = Q3 + 1.5*IQR
Outlier2 = Q1 - 1.5*IQR
print(Outlier1)
print(Outlier2)
asia[asia['Philippines']>Outlier1]
from wordcloud import WordCloud, STOPWORDS
alice_novel = open('/Users/home/Downloads/1462444-088c12e7f74fcff9be6c4faa556f961cb7a675bd/alice.txt', 'r').read()
stopwordsremove = set(STOPWORDS)
alice_wc = WordCloud(background_color = 'white', max_words = 2000,
stopwords = stopwordsremove)
alice_wc.generate(alice_novel)
plt.figure(figsize = (10,15))
plt.imshow(alice_wc)
plt.show()
stopwordsremove = set(STOPWORDS)
stopwordsremove.add('said')
alice_wc = WordCloud(background_color = 'white', max_words = 3000,
stopwords = stopwordsremove)
alice_wc.generate(alice_novel)
fig = plt.figure()
fig.set_figheight(20)
fig.set_figwidth(20)
plt.imshow(alice_wc)
plt.axis('off')
plt.show()
import folium
worldmap = folium.Map(location=[19.25, 72.86], zoom_start=15)
worldmap
worldmap = folium.Map(location=[19.25, 72.86], zoom_start=14, tiles='Stamen Toner')
worldmap
worldmap = folium.Map(location=[19.25, 72.86], zoom_start=14, tiles='Stamen Terrain')
worldmap
incidents = pd.read_csv('https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DV0101EN/labs/Data_Files/Police_Department_Incidents_-_Previous_Year__2016_.csv')
print('Dataset downloaded and read into a pandas dataframe!')
print(incidents.head())
print(incidents.shape)
limit = 100
inc = incidents.iloc[0:limit,:]
latitude = 37.77
longitude = -122.42
map1 = folium.Map(location = [latitude, longitude], zoom_start=12)
map1
#given information about city coordinates
latitude= 37.77
longitude = -122.42
#create map using folium library and Map class
map1 = folium.Map(location = [latitude, longitude], zoom_start=12)
map1
#incident we will impose on the map
incident = folium.map.FeatureGroup()
#reduce size of dataset
df1 = incidents.iloc[0:limit,:]
#loop through the crimes by their lat Y and long X and create markers
for lat, long in zip(df1.Y, df1.X):
incident.add_child(folium.CircleMarker([lat, long], radius = 5, color = 'yellow', fill=True,
fill_color='blue').add_to(incident))
#add pop ups
lats = list(df1.Y)
longs = list(df1.X)
labels = list(df1.Category)
for lat, long, labs in zip(lats, longs, labels):
folium.Marker([lat, long], popup=labs).add_to(map1)
#add incidents/crimes to the map
map1.add_child(incident)
#given information about city coordinates
latitude= 37.77
longitude = -122.42
#create map using folium library and Map class
map1 = folium.Map(location = [latitude, longitude], zoom_start=12)
map1
#incident we will impose on the map
incident = folium.map.FeatureGroup()
#reduce size of dataset
df1 = incidents.iloc[0:limit,:]
#loop through the crimes by their lat Y and long X and create markers
lats = list(df1.Y)
longs = list(df1.X)
labels = list(df1.Category)
for lat, long, labs in zip(lats, longs, labels):
folium.CircleMarker([lat, long], popup=labs, radius=5, color='yellow', fill=True,
fill_color='blue').add_to(map1)
#add incidents/crimes to the map
map1
#given information about city coordinates
latitude= 37.77
longitude = -122.42
#create map using folium library and Map class
map1 = folium.Map(location = [latitude, longitude], zoom_start=12)
map1
#incident we will impose on the map
from folium import plugins
incident = plugins.MarkerCluster().add_to(map1)
#reduce size of dataset
df1 = incidents.iloc[0:limit,:]
#loop through the crimes by their lat Y and long X and create markers
lats = list(df1.Y)
longs = list(df1.X)
labels = list(df1.Category)
for lat, long, labs in zip(lats, longs, labels):
folium.CircleMarker([lat, long], popup=labs, radius=5, color='yellow', fill=True,
fill_color='blue').add_to(incident)
#add incidents/crimes to the map
map1
canada['total_immigration'] = canada.sum(axis='columns')
canada.sort_values(by='total_immigration', ascending=False, axis='index', inplace=True)
canada.head(10)
canada.loc[canada.index.tolist(), years].transpose().plot(figsize=(15,15),legend=False);
plt.title('Immigration of 195 countries');
plt.xlabel('Years');
plt.ylabel('Immigrants');
canada.loc[['India','China','Philippines'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of India, China and Philippines');
plt.xlabel('Years');
plt.ylabel('Immigrants');
canada['avglast3'] = (canada['2011']+canada['2012']+canada['2013'])/3
l3 = canada['avglast3']
l3 = l3.sort_values(ascending = False )
l3 = l3.round()
l3 = l3[l3>2]
l3.head(10)
l5 = l3[l3<11000];
np.std(l5)
type(l5)
dl5 = df(l5)
dl5
ahg = pd.Series(range(0,12000,1630))
bins = ahg
dl5['binned'] = pd.cut(dl5['avglast3'], bins)
out = dl5['binned']
ax = out.value_counts(sort=False).plot.bar(rot=0, color="b", figsize=(16,4))
plt.show()
dl5['binned'].value_counts(sort=True)
print('(9780, 11410]')
print(' {ho} {jo}'.format(ho = l5.index[0], jo = l5[0]))
print('')
print('')
print('(8150, 9780]')
print(' {ho} {jo}'.format(ho = l5.index[1], jo = l5[1]))
print('')
print('')
print('(6520, 8150]')
print(' {ho} {jo}'.format(ho = l5.index[2], jo = l5[2]))
print('')
print('')
print('(4890, 6520]')
print(' {jo}'.format(jo = l5[3:7]))
print('')
print('')
print('(3260, 4890]')
print(' {jo}'.format(jo = l5[7:14]))
print('')
print('')
print('(1630, 3260]')
print(' {jo}'.format(jo = l5[14:28]))
print('')
print('')
print('(0, 1630]')
print(' {jo}'.format(jo = l5[28:172]))
a1 = l5[0:3].index.tolist()
canada.loc[a1, years].transpose().plot(figsize=(15,15));
plt.title('Immigration of {as1}'.format(as1 = a1));
plt.xlabel('Years');
plt.ylabel('Immigrants');
years = list(map(str,range(1980,2014)))
a2 = l5[4:14].index.tolist()
canada.loc[a2, years].transpose().plot(figsize=(15,12));
plt.title('Immigration of {as2}'.format(as2 = a2));
plt.xlabel('Years');
plt.ylabel('Immigrants');
plt.ylim((0,7000));
years1 = list(map(str,range(2000,2014)))
a4 = l5[14:28].index.tolist()
canada.loc[a4, years1].transpose().plot(figsize=(21,13));
plt.title('Immigration of {as4}'.format(as4 = a4));
plt.xlabel('Years');
plt.ylabel('Immigrants');
plt.ylim((0,6100));
a4 = l5[29:42].index.tolist()
canada.loc[a4, years1].transpose().plot(figsize=(19,13));
plt.title('Immigration of {as4}'.format(as4 = a4));
plt.xlabel('Years');
plt.ylabel('Immigrants');
plt.ylim((400,2800));
canada.loc[['India'], years].transpose().plot(figsize =(15,15));
plt.title('Immigration of India');
plt.xlabel('Years');
plt.ylabel('Immigrants');
canada.loc[['China','India'], years].transpose().plot(figsize =(15,15));
plt.title('Immigration of China and India');
plt.xlabel('Years');
plt.ylabel('Immigrants');
a9 = ['Lebanon', 'Sri Lanka']
canada.loc[['Lebanon', 'Sri Lanka'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of {as9}'.format(as9 = a9));
plt.xlabel('Years');
plt.ylabel('Immigrants');
a9 = ['Pakistan',' Republic of Korea']
canada.loc[['Pakistan', 'Republic of Korea'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of {as9}'.format(as9 = a9));
plt.xlabel('Years');
plt.ylabel('Immigrants');
years = list(map(str,range(1980,2014)))
canada.loc[['Romania'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of Romania');
plt.xlabel('Years');
plt.ylabel('Immigrants');
years = list(map(str,range(1980,2014)))
canada.loc[['Philippines'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of Philippines');
plt.xlabel('Years');
plt.ylabel('Immigrants');
years = list(map(str,range(1980,2014)))
canada.loc[['United Kingdom of Great Britain and Northern Ireland'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of United Kingdom of Great Britain and Northern Ireland');
plt.xlabel('Years');
plt.ylabel('Immigrants');
years = list(map(str,range(1980,2014)))
canada.loc[['Viet Nam'], years].transpose().plot(figsize=(15,15));
plt.title('Immigration of Viet Nam');
plt.xlabel('Years');
plt.ylabel('Immigrants');
indcri = pd.read_csv('https://storage.googleapis.com/kagglesdsdata/datasets%2F1850%2F3879%2Fcrime%2Fcrime%2F01_District_wise_crimes_committed_IPC_2001_2012.csv?GoogleAccessId=gcp-kaggle-com@kaggle-161607.iam.gserviceaccount.com&Expires=1599078097&Signature=JDSu2lsgzbxZ4cxzIe4Ib4Tm6qYbCR4DpiywJPr5tbFQyTGGv0NO19slzn%2BWP0qDORJuKwhVhjvdo3J5%2FcPfjTWnRMKLD%2FHcnlksjbB%2F9m7LE0%2FGE%2FeQt4pBmaBaVVdT6%2F944FheXw0GXFE%2BomBRJOvme9hZOxQ2rmCxj4WsxhvLEgcKvgtUKytHES%2Fl%2FMwbvtF7gYuwzmK%2BmJL9yaO%2Fqyk3vwyUjNvYo7lf%2FMpWM8YAAnyC1osbta3hMPwEsf01K27GgVhCzMOykQAB45vZUvVfRoWU3o1%2BxvHKw8kdKVCL9ZSy7tefz8IB5nPydgJv8%2Bznfqun%2BudngkGe5C%2BPZA%3D%3D')
df = indcri
indcri.head()
mumcri = df.loc[df['DISTRICT'] == 'MUMBAI']
mumcri.head(10)
mumcri.columns
plt.plot('YEAR', 'TOTAL IPC CRIMES', data=mumcri);
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from pywaffle import Waffle
%matplotlib inline
scan = canada.loc[['Sweden', 'Denmark', 'Norway'], :]
scan
cat = list(scan.index.values)
vals = scan['Total']
fig = plt.figure(FigureClass = Waffle, rows = 7, columns = 30, values = vals, labels = list(cat),
colors=["#2196f3", "#ff5252", "#999999"], figsize=(10,5),
legend = {'loc': 'lower left', 'bbox_to_anchor': (0.87, -0.4)})
indpakchi = canada.loc[['India', 'Pakistan', 'China'], :]
cat = list(indpakchi.index.values)
vals = indpakchi['Total']
fig = plt.figure(FigureClass = Waffle, rows = 7, columns = 30, values = vals, labels = list(cat),
colors=["#2196f3", "#ff5252", "#999999"], figsize=(10,5),
legend = {'loc': 'lower left', 'bbox_to_anchor': (0.878, -0.4)})